﻿// TestServer.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "MsgNode.h"
#include <iostream>
void PrintSerData(const std::vector<uint8_t>& data) {
    for (const auto& byte : data) {
        std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";
    }
    std::cout << std::dec << std::endl;
}
int main()
{
    MsgNode msgNode;
    msgNode.SetMainCommand(0x01);
	msgNode.SetDirection(0x03); // 设置方向为上行
    msgNode.SetSubCommand(0x00);
    std::vector<uint8_t> businessData = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
    msgNode.SetBusinessData(businessData);
    // 序列化消息
    std::vector<uint8_t> serializedData = msgNode.Serialize();
    // 输出序列化后的数据
	PrintSerData(serializedData);
    // 反序列化消息
    MsgNode newMsgNode;
    if (newMsgNode.Deserialize(serializedData)) {
        std::cout << "Deserialized successfully!" << std::endl;
		std::cout<<newMsgNode.toString()<<std::endl; // 打印消息信息
        const auto& deserializedData = newMsgNode.GetBusinessData();
        std::cout << "Business Data: ";
        for (const auto& byte : deserializedData) {
            std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";
        }
        std::cout << std::dec << std::endl;
    } else {
        std::cout << "Deserialization failed!" << std::endl;
    }


    MsgNode msgNode1;
    msgNode1.SetMainCommand(0x02);
    msgNode1.SetDirection(0x04); // 设置方向为上行
    msgNode1.SetSubCommand(0x00);
    //std::vector<uint8_t> businessData = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
    //msgNode.SetBusinessData(businessData);
    // 序列化消息
    std::vector<uint8_t> serializedData1 = msgNode1.Serialize();
    // 输出序列化后的数据
    PrintSerData(serializedData1);
    // 反序列化消息
    MsgNode newMsgNode1;
    if (newMsgNode1.Deserialize(serializedData1)) {
        std::cout << "Deserialized successfully!" << std::endl;
        std::cout<<newMsgNode1.toString()<<std::endl; // 打印消息信息
        const auto& deserializedData1 = newMsgNode1.GetBusinessData();
        std::cout << "Business Data: ";
        for (const auto& byte : deserializedData1) {
            std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";
        }
        std::cout << std::dec << std::endl;
    }
    else {
        std::cout << "Deserialization failed!" << std::endl;
    }



	return 0;
}
